<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="店铺id" prop="shopId">
        <el-input
          v-model.trim="queryParams.shopId"
          placeholder="请输入店铺id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model.trim="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="orderNumber">
        <el-input
          v-model.trim="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品ID" prop="productId">
        <el-input
          v-model.trim="queryParams.productId"
          placeholder="请输入商品ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>

      <div v-if="isOpen">
        <el-form-item label="商品名称" prop="productName">
          <el-input
            v-model.trim="queryParams.productName"
            placeholder="请输入商品名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="承诺发货时间" prop="commitShipmentDate">
          <el-date-picker
            clearable
            v-model="queryParams.commitShipmentDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择承诺发货时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="成交时间" prop="transactionTime">
          <el-date-picker
            clearable
            v-model="queryParams.transactionTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择成交时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发货时间" prop="estimatedShipmentDate">
          <el-input
            v-model.trim="queryParams.estimatedShipmentDate"
            placeholder="请输入发货时间"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="补偿时间" prop="compensationPeriod">
          <el-input
            v-model.trim="queryParams.compensationPeriod"
            placeholder="请输入补偿时间"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="补偿原因" prop="compensationReason">
          <el-input
            v-model.trim="queryParams.compensationReason"
            placeholder="请输入补偿原因"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="补偿金额" prop="compensationAmount">
          <el-input
            v-model.trim="queryParams.compensationAmount"
            placeholder="请输入补偿金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="逻辑删除" prop="isDelete">
          <el-input
            v-model.trim="queryParams.isDelete"
            placeholder="请输入逻辑删除"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['pdd:OvertimeDelivery:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['pdd:OvertimeDelivery:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['pdd:OvertimeDelivery:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pdd:OvertimeDelivery:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <uploadFileShopid
          @handleSuccess="getList"
          :uploadUrl="'/pdd/OvertimeDelivery/importData'"
        />
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="OvertimeDeliveryList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="店铺id" align="center" prop="shopId" />
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <el-table-column label="订单号" align="center" prop="orderNumber" />
      <el-table-column label="商品ID" align="center" prop="productId" />
      <el-table-column label="商品名称" align="center" prop="productName" />
      <el-table-column label="商品类型" align="center" prop="productType" />
      <el-table-column
        label="承诺发货时间"
        align="center"
        prop="commitShipmentDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.commitShipmentDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="成交时间"
        align="center"
        prop="transactionTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.transactionTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="发货时间"
        align="center"
        prop="estimatedShipmentDate"
      />
      <el-table-column
        label="补偿时间"
        align="center"
        prop="compensationPeriod"
      />
      <el-table-column
        label="补偿原因"
        align="center"
        prop="compensationReason"
      />
      <el-table-column
        label="补偿金额"
        align="center"
        prop="compensationAmount"
      />
      <el-table-column label="逻辑删除" align="center" prop="isDelete" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['pdd:OvertimeDelivery:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pdd:OvertimeDelivery:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改补偿-超时发货记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="店铺id" prop="shopId">
          <el-input v-model.trim="form.shopId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model.trim="form.shopName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNumber">
          <el-input
            v-model.trim="form.orderNumber"
            placeholder="请输入订单号"
          />
        </el-form-item>
        <el-form-item label="商品ID" prop="productId">
          <el-input v-model.trim="form.productId" placeholder="请输入商品ID" />
        </el-form-item>
        <el-form-item label="商品名称" prop="productName">
          <el-input
            v-model.trim="form.productName"
            placeholder="请输入商品名称"
          />
        </el-form-item>
        <el-form-item label="承诺发货时间" prop="commitShipmentDate">
          <el-date-picker
            clearable
            v-model="form.commitShipmentDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择承诺发货时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="成交时间" prop="transactionTime">
          <el-date-picker
            clearable
            v-model="form.transactionTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择成交时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发货时间" prop="estimatedShipmentDate">
          <el-input
            v-model.trim="form.estimatedShipmentDate"
            placeholder="请输入发货时间"
          />
        </el-form-item>
        <el-form-item label="补偿时间" prop="compensationPeriod">
          <el-input
            v-model.trim="form.compensationPeriod"
            placeholder="请输入补偿时间"
          />
        </el-form-item>
        <el-form-item label="补偿原因" prop="compensationReason">
          <el-input
            v-model.trim="form.compensationReason"
            placeholder="请输入补偿原因"
          />
        </el-form-item>
        <el-form-item label="补偿金额" prop="compensationAmount">
          <el-input
            v-model.trim="form.compensationAmount"
            placeholder="请输入补偿金额"
          />
        </el-form-item>
        <el-form-item label="逻辑删除" prop="isDelete">
          <el-input v-model.trim="form.isDelete" placeholder="请输入逻辑删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model.trim="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOvertimeDelivery,
  getOvertimeDelivery,
  delOvertimeDelivery,
  addOvertimeDelivery,
  updateOvertimeDelivery,
} from "@/api/pdd/OvertimeDelivery";

export default {
  name: "OvertimeDelivery",
  data() {
    return {
      isOpen: false,
      inputValue: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 补偿-超时发货记录表格数据
      OvertimeDeliveryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopId: null,
        shopName: null,
        orderNumber: null,
        productId: null,
        productName: null,
        productType: null,
        commitShipmentDate: null,
        transactionTime: null,
        estimatedShipmentDate: null,
        compensationPeriod: null,
        compensationReason: null,
        compensationAmount: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询补偿-超时发货记录列表 */
    getList() {
      this.loading = true;
      listOvertimeDelivery(this.queryParams).then((response) => {
        this.OvertimeDeliveryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        shopId: null,
        shopName: null,
        orderNumber: null,
        productId: null,
        productName: null,
        productType: null,
        commitShipmentDate: null,
        transactionTime: null,
        estimatedShipmentDate: null,
        compensationPeriod: null,
        compensationReason: null,
        compensationAmount: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelete: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加补偿-超时发货记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOvertimeDelivery(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改补偿-超时发货记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateOvertimeDelivery(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOvertimeDelivery(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除补偿-超时发货记录编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOvertimeDelivery(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "pdd/OvertimeDelivery/export",
        {
          ...this.queryParams,
        },
        `OvertimeDelivery_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
